/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2007 Miranda ICQ/IM project, 
all portions of this codebase are copyrighted to the people 
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
aLONG with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/
#pragma once

/***********************************************************************************************************
 * some compiler definitions
 ***********************************************************************************************************/
#ifdef _UNICODE
 #define _WIN32_WINNT 0x0500
#else
 #define _WIN32_WINNT 0x0400
#endif

#define _WIN32_IE	 0x0500
#define WIN32_LEAN_AND_MEAN

#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES 1

#pragma warning(disable:4995)		// disable warning about strcpy, ... is old in VC2005
#pragma warning(disable:4996)		// disable warning about strcpy, ... is old in VC2005

/***********************************************************************************************************
 * standard windows includes
 ***********************************************************************************************************/
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <stdlib.h>
#include <commctrl.h>
#include <commdlg.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <malloc.h>
#include <string>
#include <list>

using namespace std;
typedef std::basic_string<TCHAR>	tstring;

/***********************************************************************************************************
 * Miranda IM SDK includes and macros
 ***********************************************************************************************************/
#define MIRANDA_VER 0x0600

#include "m_newpluginapi.h"	// This must be included first
#include "m_win2k.h"
#include "m_button.h"
#include "m_clist.h"
#include "m_cluiframes.h"
#include "m_database.h"
#include "m_genmenu.h"
#include "m_langpack.h"
#include "m_metacontacts.h"
#include "m_protomod.h"
#include "m_protosvc.h"
#include "m_options.h"
#include "m_system.h"		// memory interface
#include "m_contacts.h"
#include "m_userinfo.h"
#include "m_userinfoex.h"
#include "m_toptoolbar.h"
#include "m_utils.h"

/***********************************************************************************************************
 * UserInfoEx plugin includes and macros
 ***********************************************************************************************************/
#include "resource.h"
#include "uinfoex_icons.h"

#include "utf8.h"
#include "mir_string.h"
#include "svcConstants.h"
#include "svcDatabase.h"
#include "dlg.h"
#include "icons.h"
#include "classMTime.h"
#include "classMAnnivDate.h"

#pragma intrinsic(memcmp, memcpy, memset, strcmp, strlen)

#define PtrIsValid(p)		(((p)!=0)&&(((HANDLE)(p))!=INVALID_HANDLE_VALUE))
#define FREE(p)				{if(PtrIsValid(p)){free((VOID*)p);(p)=NULL;}}
#define MIR_DELETE(p)		{LPVOID ptr = (LPVOID)(p);if(PtrIsValid(ptr)){delete(ptr);(ptr)=NULL;}}
#define MIR_FREE(p)			{if(PtrIsValid(p)){mir_free((VOID*)p);(p)=NULL;}}

#define GetUserData(p)		GetWindowLongPtr((p),GWL_USERDATA)
#define SetUserData(p,l)	SetWindowLongPtr((p),GWL_USERDATA,(LONG_PTR)(l))

/***********************************************************************************************************
 * UserInfoEx global variables
 ***********************************************************************************************************/
#define NAMEORDERCOUNT 8
typedef struct MGlobal {
	DWORD mirandaVersion;				// mirandaVersion
	BOOLEAN	CanChangeDetails : 1;		// is service to upload own contact information for icq present?
	BOOLEAN	HaveMetaContacts : 1;		// is meta contacts plugin installed
	BOOLEAN HaveIcoLib : 1;				// icolib plugin is present
	BOOLEAN IsCListNicer : 1;			// clist nicer is used by current user
	BOOLEAN HaveCListExtraIcons : 1;	// are extra icons supported by current clist
	BOOLEAN Reserved1 : 1;				// reserved for later use
	BOOLEAN Reserved2 : 1;				// reserved for later use
	INT		CodePage;					// codepage of the currently used langpack
	// svcContacts.cpp
	BYTE	nameOrder[NAMEORDERCOUNT];	// name order as set up for contact list
} MGLOBAL, *LPMGLOBAL;

extern HINSTANCE		ghInst;
extern MGLOBAL			myGlobals;
extern MM_INTERFACE		mmi;

/***********************************************************************************************************
 * UserInfoEx common used functions
 ***********************************************************************************************************/
DWORD	hashSetting(LPCSTR szStr);

__inline BYTE ColumnType(BYTE b) {

	if(myGlobals.IsCListNicer) {
		switch(b) {
		case 1: return 3;
		case 2: return EXTRA_ICON_ADV2;
		case 3: return 7;
		case 4: return 8;
		}
	}
	else {
		switch(b) {
		case 1: return EXTRA_ICON_ADV1;
		case 2: return EXTRA_ICON_ADV2;
		case 3: return 9;
		case 4: return 10;
		}
	}
	return 0;
}
